#pragma once

#include "vrdatacore_global.h"
#include <osg\Referenced>
#include <osg\ref_ptr>
#include "templateclass.h"
#include <QVector>
#include "datacoredefine.h"
#include <osgGA/GUIEventAdapter>
#include <osgGA/GUIEventHandler>

namespace VrDataCore
{
	class VRDATACORE_EXPORT EffectEventManager:public osg::Referenced
	{
	public:
		EffectEventManager();
		~EffectEventManager();

		bool mousePushedLeft(float,float);
		bool mousePushedRight(float,float);
		bool mousePushedMiddle(float,float);
		bool mouseReleasedLeft(float,float);
		bool mouseReleasedRight(float,float);
		bool mouseReleasedMiddle(float,float);
		bool pointerDrag(float,float);
		bool pointerMove(float,float);
		bool mouseScroll(float,float);
		bool setPointerXY(float,float);
		bool keyDown(float,float,int);
		bool keyUp(float,float,int);
		bool frame(osg::ref_ptr<osgGA::GUIEventAdapter> ea,osgGA::GUIActionAdapter* aa);
		bool handle(osg::ref_ptr<osgGA::GUIEventAdapter> ea,osgGA::GUIActionAdapter* aa);
		void reset();
		template<typename T>
		void addEventCallback(EventType type,void (T::*function)(float,float),T* obj)
		{
			FunStruct newfun;
			newfun._eventType = type;
			osg::ref_ptr<FuncBase> fb = new Type_2Func<void,T,float,float>(function,obj,0.0f,0.0f);
			newfun._fun = fb;
			_eventsVector.push_back(newfun);
		}
		template<typename T>
		void addEventCallback(EventType type,void (T::*function)(float,float,int),T* obj)
		{
			FunStruct newfun;
			newfun._eventType = type;
			osg::ref_ptr<FuncBase> fb = new Type_3Func<void,T,float,float,int>(function,obj,0.0f,0.0f,0);
			newfun._fun = fb;
			_eventsVector.push_back(newfun);
		}
		template<typename T>
		void addEventCallback(EventType type,void (T::*function)(osg::ref_ptr<osgGA::GUIEventAdapter>,osgGA::GUIActionAdapter*),T* obj)
		{
			FunStruct newfun;
			newfun._eventType = type;
			osg::ref_ptr<FuncBase> fb = new Type_2Func<void,T,osg::ref_ptr<osgGA::GUIEventAdapter>,osgGA::GUIActionAdapter*>(function,obj,0,0);
			newfun._fun = fb;
			_eventsVector.push_back(newfun);
		}
		template<typename T>
		void removeEventCallback(EventType type,T* obj)
		{
			for(int i=0;i<_eventsVector.size();++i)
			{
				if(_eventsVector.at(i)._eventType == type && obj == _eventsVector.at(i)._fun->getObject())
				{
					_eventsVector.remove(i);
					break;
				}
			}
		}
		struct FunStruct
		{
			osg::ref_ptr<FuncBase>					_fun;
			EventType								_eventType;
		};
	protected:
		QVector<FunStruct>					_eventsVector;
	};
}